<?php

namespace App\Http\Controllers\Api;

use App\Events\addLog;
use App\Http\Resources\SchoolResource;
use App\Models\School;
use Illuminate\Http\Request;
use App\Http\Controllers;
use Illuminate\Support\Facades\Auth;

class EnrollmentSituationController extends Controllers\Controller
{

    public function index()
    {
        $model = School::query()->select('upper_limit', 'registration_numbers', 'school_name')->get();
        return $model;
    }

    public function update(Request $request, $id)
    {
        $upper_limit = $request->get('upperLimit');
        $model = $this->findModel($id);
        $model->upper_limit = $upper_limit;

        $model->save();
        event(new addLog(Auth::user(),'修改'.$model->school_name.'预计招生人数'));
        return new SchoolResource($model);
    }

    public function findModel($id){
        $model = School::query()->where('id',$id)->first();
        return $model;
    }

}
